package hyo.hun.lifemanager.common;

import hyo.hun.lifemanager.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SuperActivity extends Activity {
	
	public Context superContext = this;
	
	public static Typeface typeface = null;
	
	private View titleLayout;
	private TextView titleView;
	private ViewGroup bodyLayout;
	
	public String shape;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		super.setContentView(R.layout.super_activity);
		
		titleLayout = findViewById(R.id.super_activity_titleLayout);
		titleView = (TextView) findViewById(R.id.super_activity_titleView);
		bodyLayout = (ViewGroup) findViewById(R.id.super_activity_bodyLayout);
		
	}
	
	@Override
	public void setContentView(int layoutResID)
	{
		LayoutInflater inflater = getLayoutInflater();
		View view = inflater.inflate(layoutResID, null);
		this.setContentView(view);
	}
	
	@Override
	public void setContentView(View view) {
		this.bodyLayout.removeAllViews();
		
		if(view==null)
		{
			return;
		}
		
		ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
		
		if(layoutParams == null)
		{
			layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		}
		else
		{
			layoutParams.width = LayoutParams.FILL_PARENT;
			layoutParams.height = LayoutParams.FILL_PARENT;
		}
		
		view.setLayoutParams(layoutParams);
		
		this.bodyLayout.addView(view);
		
//		SharedPreferences pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
//		int fontFlag = pref.getInt(BDConstents.FONT_SETTING, 1);
//		
//		if (fontFlag == 1)
//		{
//			if (typeface == null)
//				typeface = Typeface.createFromAsset(getAssets(), BDConstents.FONT_FILE_NAME);
//			
//			ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
//			setGlobalFont(root);  
//		}
	}
	
//	private void setGlobalFont(ViewGroup root) 
//	{
//	    for (int i = 0; i < root.getChildCount(); i++) 
//	    {
//	        View child = root.getChildAt(i);
//	        
//	        if (child instanceof TextView)
//	        {
//	        	((TextView)child).setTypeface(typeface);
//	        }
//	        else if (child instanceof EditText)
//			{
//	        	((EditText)child).setTypeface(typeface);
//			}
//	        else if (child instanceof Button)
//			{
//	        	((Button)child).setTypeface(typeface);
//			}
//	        else if (child instanceof ViewGroup)
//	        {
//	        	setGlobalFont((ViewGroup)child);
//	        }
//	    }
//	}
	
	@Override
	public void setTitle(CharSequence title)
	{
		titleView.setText(title);
	}

	@Override
	public void setTitle(int titleId)
	{
		titleView.setBackgroundResource(titleId);
	}
	
	public void setGoneTitle()
	{
		titleLayout.setVisibility(View.GONE);
	}
}
